<%@ page import="com.raise.drive.model.domain.Vehicle" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jspf/include.jspf" %>

<%--@elvariable id="instructorForm" type="com.raise.drive.web.form.InstructorForm"--%>
<%--@elvariable id="dateFormat" type="java.lang.String"--%>

<tiles:insertDefinition name=".base">

    <tiles:putAttribute name="pageTitle">
        <fmt:message key="page.fillCarInfo.title"/>
    </tiles:putAttribute>

    <tiles:putAttribute name="javascript">
        <script type="text/javascript">
            // <![CDATA[

            var curCar = 0;

            function addCar() {
                if (curCar < 9) {
                    $('additionalCar-' + curCar).style.display = 'block';
                    $('usedVehicle-' + curCar).value = 'true';
                    curCar++;
                }
            }

            function removeCar() {
                if (curCar > 0) {
                    curCar--;
                    $('additionalCar-' + curCar).style.display = 'none';
                    $('usedVehicle-' + curCar).value = 'false';
                }
            }


            // ]]>
        </script>
    </tiles:putAttribute>

    <tiles:putAttribute name="menu">
        <%@ include file="/WEB-INF/jspf/anonymousMenu.jspf" %>
    </tiles:putAttribute>

    <tiles:putAttribute name="body">

        <p>
            <fmt:message key="page.fillCarInfo.description"/>
        </p>

        <form:form commandName="instructorForm">

            <table>
                <tr>
                    <td colspan="2">
                        <tags:button key="page.fillCarInfo.addCar" onclick="addCar();"/>
                        <tags:button key="page.fillCarInfo.removeCar" onclick="removeCar();"/>
                    </td>
                </tr>
                <tr>
                    <td>
                        <fmt:message key="entity.vehicle.vendor"/><tags:required/>
                    </td>
                    <td>
                        <form:select path="vehicle.vendor">
                            <form:options items="${carVendors}" itemLabel="name" itemValue="name"/>
                        </form:select>
                    </td>
                </tr>
                <tr>
                    <td>
                        <fmt:message key="entity.vehicle.model"/><tags:required/>
                    </td>
                    <td>
                        <form:input path="vehicle.model"/>
                    </td>
                </tr>
                <tr>
                    <td>
                        <fmt:message key="entity.vehicle.gearBox"/><tags:required/>
                    </td>
                    <td>
                        <form:radiobutton path="vehicle.gearBox" value="<%=Vehicle.GearBox.MT%>"/><fmt:message
                            key="entity.vehicle.gearBox.MT"/><br/>
                        <form:radiobutton path="vehicle.gearBox" value="<%=Vehicle.GearBox.AT%>"/><fmt:message
                            key="entity.vehicle.gearBox.AT"/>
                    </td>
                </tr>
                <tr>
                    <td>
                        <fmt:message key="entity.vehicle.pricePerHour"/><tags:required/>
                    </td>
                    <td>
                        <form:input path="vehicle.pricePerHour" size="7" maxlength="5"/>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        <form:checkbox path="vehicle.additionalPedals"/><fmt:message
                            key="entity.vehicle.additionalPedals"/>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        <form:checkbox path="vehicle.additionalMirrors"/><fmt:message
                            key="entity.vehicle.additionalMirrors"/>
                    </td>
                </tr>

                    <%-- Additional vehicles --%>
                <c:forEach begin="0" end="9" step="1" varStatus="varStatus">
                    <tr>
                        <td colspan="2">
                            <table width="100%" id="additionalCar-${varStatus.index}" style="display:none;">
                                <tr>
                                    <td colspan="2">
                                        <hr/><form:hidden id="usedVehicle-${varStatus.index}" path="usedVehicle[${varStatus.index}]"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <fmt:message key="entity.vehicle.vendor"/><tags:required/>
                                    </td>
                                    <td>
                                        <form:select path="additionalVehicles[${varStatus.index}].vendor">
                                            <form:options items="${carVendors}" itemLabel="name" itemValue="name"/>
                                        </form:select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <fmt:message key="entity.vehicle.model"/><tags:required/>
                                    </td>
                                    <td>
                                        <form:input path="additionalVehicles[${varStatus.index}].model"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <fmt:message key="entity.vehicle.gearBox"/><tags:required/>
                                    </td>
                                    <td>
                                        <form:radiobutton path="additionalVehicles[${varStatus.index}].gearBox"
                                                          value="<%=Vehicle.GearBox.MT%>"/><fmt:message
                                            key="entity.vehicle.gearBox.MT"/><br/>
                                        <form:radiobutton path="additionalVehicles[${varStatus.index}].gearBox"
                                                          value="<%=Vehicle.GearBox.AT%>"/><fmt:message
                                            key="entity.vehicle.gearBox.AT"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <fmt:message key="entity.vehicle.pricePerHour"/><tags:required/>
                                    </td>
                                    <td>
                                        <form:input path="additionalVehicles[${varStatus.index}].pricePerHour" size="7"
                                                    maxlength="5"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        &nbsp;
                                    </td>
                                    <td>
                                        <form:checkbox
                                                path="additionalVehicles[${varStatus.index}].additionalPedals"/><fmt:message
                                            key="entity.vehicle.additionalPedals"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        &nbsp;
                                    </td>
                                    <td>
                                        <form:checkbox path="additionalVehicles[${varStatus.index}].additionalMirrors"/><fmt:message
                                            key="entity.vehicle.additionalMirrors"/>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </c:forEach>

                <tr>
                    <td colspan="2">
                        <tags:submit key="common.back" name="_target0"/>
                        <tags:submit key="common.next" name="_target2"/>
                        <tags:submit key="common.cancel" name="_cancel"/>
                    </td>
                </tr>

            </table>
        </form:form>

    </tiles:putAttribute>

</tiles:insertDefinition>
